package com.cade.agriculturemall.view.refresh;

import android.content.Context;
import android.view.LayoutInflater;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.cade.agriculturemall.R;
import com.xjy.widget.bounce.pull.IPullPart;

/**
 * Created by tom on 17/7/11.
 */

public class RefreshHeader extends RelativeLayout implements IPullPart {

    private TextView mTextView;
    private RefreshAnimationView mRefreshAnimationView;

    public RefreshHeader(Context context) {
        super(context);
        LayoutInflater.from(context).inflate(R.layout.refresh_header, this, true);
        mTextView = (TextView) findViewById(R.id.text_view);
        mRefreshAnimationView = (RefreshAnimationView) findViewById(R.id.title);
    }

    @Override
    public void onReset() {
        mTextView.setVisibility(GONE);
        mRefreshAnimationView.setVisibility(VISIBLE);
        setText("下拉刷新");
    }

    @Override
    public void onPrepare() {
        setText("松开刷新");
    }

    @Override
    public void onRelease() {
        setText("正在刷新...");
        mRefreshAnimationView.startAnimation();
    }

    @Override
    public void onComplete() {
        mRefreshAnimationView.setVisibility(GONE);
        mTextView.setVisibility(VISIBLE);
        setText("刷新完成");
        mRefreshAnimationView.cancel();
    }

    @Override
    public void onPositionChange(float currentY) {
        mRefreshAnimationView.setRectAlpha(currentY / getHeight());
    }

    @Override
    public void onNoMoreData() {
        setText("没有更多数据");
    }

    private void setText(String text) {
        mTextView.setText(text);
    }
}
